﻿@using TdolDemo_QBZ.Models.Task;

@{
    ViewData["Title"] = "TaskList";
}
<h2>@ViewData["Title"]</h2>
<h3>@ViewData["Message"]</h3>
<style>
    input {
        width: 100%;
        overflow-x: visible;
        overflow-y: visible;
    }
    .del {
        color:#ff6a00;
    }
</style>
<p>Use this area to provide additional information.</p>
<form action="/Home/AddTask/">

    <table>

        <thead>
            <tr>
                <th>TaskId</th>
                <th>TestDateId</th>
                <th>RegionId</th>
                <th>Remarks</th>
                <th>Status</th>
                <th>OpenIntervalStart</th>
                <th>OpenIntervalEnd</th>
                <th>CreateBy</th>
                <th>Description</th>
                <th>CreateOn</th>
                <th>units(date,type)</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td></td>
                <td><input name="TestDateId" /></td>
                <td><input name="RegionId" /></td>
                <td><input name="Remarks" /></td>
                <td><input name="Status" /></td>
                <td><input name="OpenIntervalStart" /></td>
                <td><input name="OpenIntervalEnd" /></td>
                <td><input name="CreateBy" /></td>
                <td><input name="Description" /></td>
                <td><input type="submit" value="新增"/></td>
                <td></td>
            </tr>

            @foreach (var task in ViewData["taskList"] as List<TaskWithUnitModel>)
            {
            <tr>
                <td>
                    @task.TaskId <br />
                    <span href="#" data-taskid="@task.TaskId" class="del">delate</span>
                </td>
                <td>@task.TestDateId </td>
                <td>@task.RegionId </td>
                <td>@task.Remarks </td>
                <td>@task.Status </td>
                <td>@task.OpenIntervalStart.ToShortDateString() </td>
                <td>@task.OpenIntervalEnd.ToShortDateString() </td>
                <td>@task.CreateBy </td>
                <td>@task.Description </td>
                <td>@task.CreateOn.Value.ToShortDateString() </td>
                <td>
                    @foreach (var unit in task.units)
                    {
                        @unit.WorkUnitTime.ToShortDateString()
                        <span>-</span>
                        @unit.UnitType
                        <br />
                    }

                </td>

            </tr>
            }
        </tbody>

    </table>
</form>
<script>
    setTimeout(function () {
        $("td .del").click(function (e) {
            var taskid = e.currentTarget.dataset.taskid
            if (confirm("确定要删除task" + taskid + "吗？") == true) {
                $.getJSON("/Home/DelateTask/?taskid=" + taskid, function (data) {
                    alert(data);
                    window.location.reload();
                })
            }
        });
    },1000)
</script>